package com.pet.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pet.service.SysDoctorService;
import com.pet.system.SysDoctor;
import com.pet.system.SysPet;
import com.pet.utils.Result;
import com.pet.vo.SysDoctorQueryVo;
import com.pet.vo.SysPetQueryVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author whd
 * @since 2023-08-03
 */
@RestController
@RequestMapping("/lovePet/system/sysDoctor")
public class SysDoctorController {


    @Autowired
    private SysDoctorService sysDoctorService;

    @GetMapping("/findAll")
    public Result findAll() {
        List<SysDoctor> list = sysDoctorService.list();
        return Result.ok(list);
    }


    //分页和条件查询
    @ApiOperation("分页和条件查询")
    @PostMapping("{page}/{limit}")
    public Result selectDataPageByVo(@PathVariable Long page,
                                     @PathVariable Long limit,
                                     @ApiParam("包装的查询分类名称名称") @RequestBody SysDoctorQueryVo sysDoctorQueryVo) {
        System.out.println("=========" + sysDoctorQueryVo.getName());
        IPage<SysDoctor> iPage = new Page<>(page, limit);
        iPage = this.sysDoctorService.selectpage(iPage, sysDoctorQueryVo);
        return Result.ok(iPage);
    }


    // 添加宠物
    @PostMapping("/addData")
    public Result addData(@RequestBody SysDoctor sysDoctor) {
        boolean b = this.sysDoctorService.save(sysDoctor);
        return b ? Result.ok() : Result.fail();
    }

    //根据id获取宠物
    @GetMapping("/findDataById/{id}")
    public Result findDataById(@PathVariable Long id) {
        SysDoctor sysDoctor = this.sysDoctorService.getById(id);
        return Result.ok(sysDoctor);
    }


    // 实现修改
    @PostMapping("/updateData")
    public Result updateData(@RequestBody SysDoctor sysDoctor) {
        boolean b = this.sysDoctorService.updateById(sysDoctor);
        return b ? Result.ok() : Result.fail();

    }

    @ApiOperation("根据id去移除一个宠物")
    @DeleteMapping("/removeDataById/{id}")
    public Result removeDataById(@PathVariable Long id) {
        boolean b = this.sysDoctorService.removeById(id);
        return b ? Result.ok() : Result.fail();
    }

}

